/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * busquedadvehiculo.java
 *
 * Created on 25/11/2010, 11:48:34 AM
 */

package GUI.ambulatorio;


import GUI.ambulatorio.*;
import javax.swing.JOptionPane;
import cprincipal.*;
import Persistencia.*;
import venehealthfinal.Validar;
import java.util.Date;
import java.io.*;




/**
 *
 * @author Administrador
 */
public class busquedaVehiculo extends javax.swing.JFrame {

    /** Creates new form busquedadvehiculo */
    public busquedaVehiculo() {
        initComponents();
    }

      private boolean resultado = false;
    AmbulanciaAereaXmlAmbulatorio datosAmbulancia=new AmbulanciaAereaXmlAmbulatorio();
    AmbulanciaCompactaXmlAmbulatorio datosCompacta=new AmbulanciaCompactaXmlAmbulatorio();
     AmbulanciaTerrestreXmlAmbulatorio datosTerre=new AmbulanciaTerrestreXmlAmbulatorio();
              Date d=new Date();
		int hora =d.getDate();




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jToggleButton2 = new javax.swing.JToggleButton();
        jButton2 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setForeground(new java.awt.Color(255, 0, 51));
        jLabel1.setText("Busqueda de vehiculo");

        jLabel2.setText("Tipo de vehiculo:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Vehiculo", "Ambulancia ", "Helicoptero", " ", " " }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Placa");

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jToggleButton2.setText("Cancelar");
        jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton2ActionPerformed(evt);
            }
        });

        jButton2.setText("Buscar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Ambulatorio El Hatillo", "Ambulatorio Los Pomelos", "Ambulatorio Maria Jose\t", "Ambulatorio San Antonio" }));

        jLabel4.setText("Seleccione Ambulatorio:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4))
                                .addGap(41, 41, 41)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(jButton2)
                        .addGap(28, 28, 28)
                        .addComponent(jToggleButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jToggleButton2))
                .addGap(30, 30, 30))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
      ambulatorio ventana= new ambulatorio();
      ventana.setVisible(true);
      this.dispose();
    }//GEN-LAST:event_jToggleButton2ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
   String prueba = jComboBox1.getSelectedItem().toString();
    String prueba2 = jComboBox2.getSelectedItem().toString();
       
       

        if (jTextField1.getText().isEmpty()){
            JOptionPane.showMessageDialog(null, "Error, campo invalidos", "Debe indicar un numero de Matricula valido", JOptionPane.ERROR_MESSAGE);
        } else {
            int valor = Validar.ValidarEntero(jTextField1.getText(), "Matricula no es numÃ©rica");
            if (valor == 1) {
                        boolean flag = false;
                      if(prueba.equals("Helicoptero")){
                    ambulanciaAerea aereo = datosAmbulancia.buscarAmbulanciaAerea(Integer.parseInt(jTextField1.getText()),jComboBox2.getSelectedItem().toString());
                    if (aereo!=null){
                        ambulanciaAereaAmbulatorio ventana =  new ambulanciaAereaAmbulatorio(aereo);
                        ventana.setVisible(true);
                        this.dispose();
                        flag=true;
                          }
                    }

                        if(prueba.equals("Vehiculo")){
                                        ambulanciaCompacta comp = datosCompacta.buscarAmbulanciaCompacta(Integer.parseInt(jTextField1.getText()), jComboBox2.getSelectedItem().toString());
                                     if (comp!=null){
                                        ambulanciaCompactaRegistro ventana =  new ambulanciaCompactaRegistro(comp);
                                        ventana.setVisible(true);
                                        this.dispose();
                                        flag=true;
                                         }
                           }

               
                      if(prueba.equals("Ambulancia") /*|| (flag==false)*/){
                           ambulanciaTerrestre terr = datosTerre.buscarAmbulanciaTerrestre(Integer.parseInt(jTextField1.getText()), jComboBox2.getSelectedItem().toString());
                           if (terr!=null){
                             int y = terr.getFecha();
                                    int total=y-hora;
                                      System.out.println("numero:"+ hora);

                                            if((y-hora)==1){
                                                     int seleccion = JOptionPane.showOptionDialog(
                                                     jButton2,
                                                     "La Ambulancia se encuentra en Mantenimiento seleccione si desea ir a:",
                                                     "Mensaje de Advertencia",
                                                     JOptionPane.YES_NO_CANCEL_OPTION,
                                                     JOptionPane.QUESTION_MESSAGE,
                                                     null,    // null para icono por defecto.
                                                    new Object[] { "Informacion Ambulancia", "Registro Taller" },   // null para YES, NO y CANCEL
                                                     "Informacion Ambulancia");

                                                 if (seleccion == 0){
                                                  ambulaciaTerrestreAmbulatorio ventana =  new ambulaciaTerrestreAmbulatorio(terr);
                                                      ventana.setVisible(true);
                                                              this.dispose();
                                                }
                                                    else{
                                                              registroTallerTerrestre ventana=new registroTallerTerrestre(terr);
                                                                 ventana.setVisible(true);
                                                                      this.dispose();
                                                    }
                                             }

                          }
                         }

                        if (flag!=true)
                            JOptionPane.showMessageDialog(null, "Matricula no Existe", "Error Matricula no encontrada", JOptionPane.ERROR_MESSAGE);
                     
        }
       
           }
      
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new busquedaVehiculo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton2;
    // End of variables declaration//GEN-END:variables

}
